const express = require('express');
const db = require('../uilit/mysql');

const router=express.Router();

// 获取前端传递的招聘信息数据，保存在招聘信息表中
router.post('/addjob',(req,res)=>{
    const sqlpro=`select pro_id from province where pro_name='${req.body.province}';`;
    const sqlcity=`select city_id from city where city_name='${req.body.city}';`;
    const sqlarea=`select area_id from area where area_name='${req.body.area}';`;
    db.query(sqlpro,(err1,data1)=>{
        if(err1){
            console.log(err1);
        }else{
            db.query(sqlcity,(err2,data2)=>{
                if(err2){
                    console.log(err2);
                }else{
                    db.query(sqlarea,(err3,data3)=>{
                        if(err3){
                            console.log(err3);
                        }else{
                            const sqljob=`insert into job values(NUll,${parseInt(req.body.id)},'${req.body.job}','${req.body.agerequire}',
                                         '${req.body.edurequire}','${req.body.jobyear}','${req.body.hiringnum}','${req.body.jobrequire}',
                                         '${req.body.money}','${req.body.time}','${req.body.good}','${req.body.othergood}',${data1[0].pro_id},
                                         ${data2[0].pro_id},${data3[0].pro_id}.'${req.body.address}','${req.body.date}');`
                            db.query(sqljob,(err)=>{
                                if(err){
                                    console.log(err);
                                }else{
                                    res.send({code:res.statusCode,msg:'保存成功！'});
                                }
                            });
                        }
                    })
                }
            })
        }
    })







    
});

module.exports=router;